﻿/*=============================================================================== 
 * SQLHelper.cs
 * author:csyingwu
 * 
 * 
 * 
 */
//============================================================================
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace Kaidou.Util
{
    public class CheckUnit
    {
        public static bool CheckMustInput(string strInput)
        {
            if (string.IsNullOrEmpty(strInput))
            { 
                return false; 
            }
            else
            {
                return true;
            }
        }
        public static bool CheckByteLength(int maxLength, string strInput)
        {
            if (Encoding.Default.GetBytes(strInput).Length > maxLength)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        public static bool CheckLength(int maxLength, string strInput)
        {
            if (strInput.Length > maxLength)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        public static bool CheckPassword(string strInput)
        {

            string pattern = @"^[A-Za-z0-9]+$";
            Regex reg = new Regex(pattern);
            if (!reg.Match(strInput).Success && strInput != "")
            {
                return false;
            }
            else
            {

                return true;
            
            }
        }
        public static bool CheckYear(string strInput)
        {

            string pattern = @"^\d{4}$";

            string pattern2 = @"^[0-9]*$";

            Regex reg = new Regex(pattern);
            Regex reg2 = new Regex(pattern2);

            if ((!reg.IsMatch(strInput) || !reg2.IsMatch(strInput)) && strInput != "")
            {

                return false;

            }
            else
            {
                return true;
            
            }

        }

        public static bool CheckDatetime(string strInput)
        {


            string pattern = @"(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)";
            Regex reg = new Regex(pattern);
            if (!reg.IsMatch(strInput))
            {
                return false;

            }
            else
            {
                return true;
            
            }



        }

        public static bool CheckIsDecimal(string strInput)
        { 
            decimal outDec;
            return decimal.TryParse(strInput, out outDec);
        }
        public static bool CheckIsInt(string strInput)
        {
            int outInt;
            return int.TryParse(strInput, out outInt);
        }
    }
}
